<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
<link href="../css/laydate.css" rel="stylesheet"/>
<link href="../css/lay.css" rel="stylesheet"/>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery-1.8.3.js"></script>
	<script src="${pageContext.request.contextPath}/js/laydate.js"></script>
</head>
<body>
	<div id="updateDiv" align="center"><!-- 新增DIV -->
		
		<form name="addf" action="" method="post" enctype="multipart/form-data" target="hideframe">
		<!-- 需要进行表单封装 -->
		<table>
		<input type="hidden" name="userId" value="${userTable.user_id }"><br>
		<%-- <input type="hidden" name="userAcount" value="${userTable.user_account }"> --%>
		
		<tr><td align="right">用户名：</td>
		    <td align="left"><input type="text" name="userAccount" value="${userTable.user_account }"></td>
		</tr>
        <tr><td align="right">性别：</td>
           <td align="left"><input type="radio" id='isNan' name="userSex" value='1' >男
                 <input type="radio" id='isNv' name="userSex" value='0'>女</td>
         </tr>        
        <tr><td align="right">邮箱：</td>
          <td align="left"><input type="text" name="userEmail" value="${userTable.user_email }"></td>
        </tr>
        <tr><td align="right">年龄：</td>
            <td align="left"><input type="text" name="userAge" value="${userTable.user_age }"></td>
        </tr>
		<tr><td align="right">密码：</td>
		     <td align="left"><input type="password" name="userPass" value="${userTable.user_pass }"></td>
		</tr> 
		<tr><td align="right">状态：</td>
		   <td align="left"><input type="radio" id='isUser' name="userState" value='1' >在用<input type="radio" id='isnotUser' name="userState" value='0'>停用</td>
		</tr>
		
		<tr><td align="right">出生日期：</td>
		     <td align="left"><input type="text" name="userBirthday" value="${userTable.user_birthday }" id="demo"></td>
		</tr>
		
		<tr><td colspan="2" align="center"><input type="button" onclick = "updateUser()" value="修改"></td></tr>
		</table>
	</form>
	</div>
	<div id="showAllMessage">
	</div>
	<iframe name="hideframe" style="display:none"></iframe> <!-- 此iframe不显示 -->
</body>
<script type="text/javascript">
	//用来给单选钮赋初始值
	var user_state = "${userTable.user_state }";
	if(user_state == 1){
		document.getElementById("isUser").checked = true;
	}else{
		document.getElementById("isnotUser").checked = true;
	}
	var user_sex = "${userTable.user_sex }";
	if(user_sex == 1){
		document.getElementById("isNan").checked = true;
	}else{
		document.getElementById("isNv").checked = true;
	}
	
	//end
	function updateUser(){//进行新增操作（需要上传图片，我们要确保上传图片的提交不能够进行跳转，所以在表单中没有设置提交按钮）
		var userId = addf.userId.value;//取得userId控件的值
		var userAccount = addf.userAccount.value;//取得userAcount控件的值
		var userSex = addf.userSex.value;
		var userEmail = addf.userEmail.value;
		var userAge = addf.userAge.value;
		var userPass  = addf.userPass.value;//取得密码	
		var userState = addf.userState.value;
		var userBirthday = addf.userBirthday.value;
		addf.submit();//表单提交，表单提交的时候，跳转的目标是隐藏iframe，那么页面就没有跳转的效果，但是提交之后文件是已经上传了的。
		
		$.ajax({//进行提交
			type : "post",//提交方式
			url : "${pageContext.request.contextPath}/servlet/updateUser",//提交路径
			async : true,//是否异步
			dataType : 'json',//数据格式（不进行跨越json，跨域使用jsonp），
			data : { //参数			
				userId : userId,
				userAccount : userAccount,
				userSex : userSex,
				userEmail : userEmail,
				userAge : userAge,
				userPass : userPass,
				userState : userState,
				userBirthday : userBirthday
			},
			success : function(data) {//执行成功后调用的方法
					if(data[0].flag == true){
						alert("修改成功");
					}else{
						alert("修改失败");
					}		
					$("#showAllMessage").slideDown("slow");//显示消息
				},
			error : function(err) {//执行失败后的失败信息的显示
				console.log(err);
			}
		});
	}
	function closeMessage(){//关闭消息
		$("#showAllMessage").hide();//隐藏消息
	}
	function back(){
		//window.history.query(0);
		parent.query(0);//刷新之前页面 
		window.close();//返回之前查询界面
		/* $("#pageDiv").fadeIn();
		$("#addDiv").hide(); */
		 //query(0);
	}
	;!function(){
		laydate({
		   elem: '#demo'
		})
		}();
</script>
</html>